export class SelectionUtils {
  /**
   * 获取当前文本选择
   */
  static getCurrentSelection(): Selection | null {
    return window.getSelection()
  }

  /**
   * 获取选中的文本内容
   */
  static getSelectedText(): string {
    const selection = this.getCurrentSelection()
    return selection ? selection.toString() : ''
  }

  /**
   * 清空当前选择
   */
  static clearSelection(): void {
    const selection = this.getCurrentSelection()
    selection?.removeAllRanges()
  }

  /**
   * 检查是否有文本被选中
   */
  static hasSelection(): boolean {
    const selection = this.getCurrentSelection()
    return selection ? selection.toString().length > 0 : false
  }
}
